package com.datasync.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.datasync.common.annotation.Log;
import com.datasync.common.core.controller.BaseController;
import com.datasync.common.core.domain.AjaxResult;
import com.datasync.common.enums.BusinessType;
import com.datasync.system.domain.SErrorLog;
import com.datasync.system.service.ISErrorLogService;
import com.datasync.common.utils.poi.ExcelUtil;
import com.datasync.common.core.page.TableDataInfo;

/**
 * 同步失败日志记录Controller
 * 
 * @author ruoyi
 * @date 2023-05-05
 */
@RestController
@RequestMapping("/system/log")
public class SErrorLogController extends BaseController
{
    @Autowired
    private ISErrorLogService sErrorLogService;

    /**
     * 查询同步失败日志记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:log:list')")
    @GetMapping("/list")
    public TableDataInfo list(SErrorLog sErrorLog)
    {
        startPage();
        List<SErrorLog> list = sErrorLogService.selectSErrorLogList(sErrorLog);
        return getDataTable(list);
    }

    /**
     * 导出同步失败日志记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:log:export')")
    @Log(title = "同步失败日志记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SErrorLog sErrorLog)
    {
        List<SErrorLog> list = sErrorLogService.selectSErrorLogList(sErrorLog);
        ExcelUtil<SErrorLog> util = new ExcelUtil<SErrorLog>(SErrorLog.class);
        util.exportExcel(response, list, "同步失败日志记录数据");
    }

    /**
     * 获取同步失败日志记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:log:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sErrorLogService.selectSErrorLogById(id));
    }

    /**
     * 新增同步失败日志记录
     */
    @PreAuthorize("@ss.hasPermi('system:log:add')")
    @Log(title = "同步失败日志记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SErrorLog sErrorLog)
    {
        return toAjax(sErrorLogService.insertSErrorLog(sErrorLog));
    }

    /**
     * 修改同步失败日志记录
     */
    @PreAuthorize("@ss.hasPermi('system:log:edit')")
    @Log(title = "同步失败日志记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SErrorLog sErrorLog)
    {
        return toAjax(sErrorLogService.updateSErrorLog(sErrorLog));
    }

    /**
     * 删除同步失败日志记录
     */
    @PreAuthorize("@ss.hasPermi('system:log:remove')")
    @Log(title = "同步失败日志记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sErrorLogService.deleteSErrorLogByIds(ids));
    }
}
